const app = getApp()
const api = app.globalData.api

Page({

  /**
   * 页面的初始数据
   */
  data: {
    monthCollocation:[1,2,3,4,5,6,7,8,9,10,11,12],
    year:'',
    monthIndex:1,
    info:{},
    record:[],
    tabIndex:0,
    salaryType:'综合工资',
    month:'',
    list:[]
  },

  /**
   * 月份点击事件
   */
  monthClick:function(e){
    let index = e.currentTarget.dataset.index;
    let month = this.data.year+'-'+(index<10?('0'+index):index);
    this.setData({
      monthIndex:index,
      month:month
    })
   
   this.requestData(this.data.salaryType)

  },
 
  bindYearChange:function(e){
    let year = e.detail.value
    let month=year+'-01';
    this.setData({
      year:year,
      month:month
    })
    
    this.requestData(this.data.salaryType)

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let date = new Date();
    this.setData({
      year:date.getFullYear()
    })
    this.requestData();
  },
  confirm(){
    let that = this;
    let id = api.isBlank(this.data.info.id)?'':this.data.info.id;
    api.curlPost('?cla=paySlipApp&fun=confirmEdit',{id:id}).then((res)=>{
      that.requestData(that.data.salaryType)
    })
  },
  requestData(type='综合工资'){
    let that = this;
    let month = this.data.month;
    api.curlPost('?cla=paySlipApp&fun=home',{type:type,month:month}).then((res)=>{
      if(that.data.salaryType =='计时计件'){
        console.log(111)
        that.setData({
          list:res.data.result,
        })
      }else{
        that.setData({
          info:res.data.result,
          record:res.data.record
        })
      }
      
    })
  },
  /**标签页切换 */
  tabChange(e){

    this.setData({
      tabIndex:e.detail.name,
      salaryType:e.detail.title
    })
    this.requestData(e.detail.title);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})